package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.WechatConfigService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.WechatConfigAddVO;
import com.junzhiit.nengji.cms.web.vo.WechatConfigEditVO;
import com.junzhiit.nengji.cms.web.vo.WechatConfigVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/wechat/config")
public class WechatConfigController extends BaseController {

	@Autowired
	private WechatConfigService wechatConfigService;

	@ApiOperation(value = "获取所有微信配置列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, WechatConfigVO wcVO) {
		return wechatConfigService.findAll(dtp, wcVO);
	}

	@ApiOperation(value = "根据ID查询微信配置")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		AssertUtil.notBlank(id, "id is required.");
		return wechatConfigService.findById(id);
	}

	@ApiOperation(value = "创建微信配置")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(WechatConfigAddVO wechatConfigAddVO) {
		AssertUtil.notBlank(wechatConfigAddVO.getCsId(), "shopId or chainId is required.");
		AssertUtil.notBlank(wechatConfigAddVO.getAppId(), "appId is required.");
		AssertUtil.notBlank(wechatConfigAddVO.getPartner(), "partner is required.");
		AssertUtil.notBlank(wechatConfigAddVO.getSecret(), "secret is required.");
		AssertUtil.notBlank(wechatConfigAddVO.getPaySecret(), "paySecret is required.");
		return wechatConfigService.add(wechatConfigAddVO);
	}

	@ApiOperation(value = "修改微信配置")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(WechatConfigEditVO wechatConfigEditVO) {
		AssertUtil.notBlank(wechatConfigEditVO.getCsId(), "shopId or chainId is required.");
		AssertUtil.notBlank(wechatConfigEditVO.getAppId(), "appId is required.");
		AssertUtil.notBlank(wechatConfigEditVO.getPartner(), "partner is required.");
		AssertUtil.notBlank(wechatConfigEditVO.getSecret(), "secret is required.");
		AssertUtil.notBlank(wechatConfigEditVO.getPaySecret(), "paySecret is required.");
		return wechatConfigService.edit(wechatConfigEditVO);
	}

	@ApiOperation(value = "删除微信配置")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return wechatConfigService.delete(id);
	}
}
